# -*- coding: utf-8 -*-
import os ,sys,datetime
import time


import os
import shutil

import oss2

access_key_id = os.getenv('OSS_TEST_ACCESS_KEY_ID', 'Lt3tTAIAqgrg0qh5')
access_key_secret = os.getenv('OSS_TEST_ACCESS_KEY_SECRET', 'bowrqEK0na4463HCNFWYU3xLqWgdoH')
bucket_name = os.getenv('OSS_TEST_BUCKET', 'backupbluk654')
#endpoint = os.getenv('OSS_TEST_ENDPOINT', 'http://oss-cn-shanghai.aliyuncs.com')
endpoint = os.getenv('OSS_TEST_ENDPOINT', 'http://oss-cn-shanghai.aliyuncs.com/mars1')

for param in (access_key_id, access_key_secret, bucket_name, endpoint):
    assert '<' not in param, '请设置参数：' + param


bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name)
path1="d:\\test1"
for f in os.listdir(path1):
    file= path1 + os.sep + f

    lastmtime = os.stat(file).st_ctime

    now1 = time.time() - lastmtime
    if now1 < 86400:
        print now1
        print f
        print file
        print lastmtime
        bucket.put_object_from_file('mars233/' + f,file
                                   )
        print 'upload ok'

    if now1 > 200000:
        print file
        os.remove(file)
        print file + 'removed'

print "finish"